<?php

class Core_Services_User_VO
{
	/**
	 * The AMF Type mapping
	 *
	 * @var string
	 */
	public $_explicitType = 'UserVO';

	/**
	 * The Unique Database Identifier for this user
	 *
	 * @var int
	 */
	public $id;

	/**
	 * The Name for this user.
	 *
	 * @var string
	 */
	public $login;

	/**
	 * The First Name of the user
	 *
	 * @var string
	 */
	public $firstName;

	/**
	 * The Last Name of the user
	 *
	 * @var string
	 */
	public $lastName;

	/**
	 * The Email Address for this user.
	 *
	 * @var string
	 */
	public $email;

	/**
	 * When this user was created.
	 *
	 * @var string
	 */
	public $created;

	/**
	 * The last time this user was updated.
	 *
	 * @var string
	 */
	public $updated;

	/**
	 * The spam flag
	 *
	 * @var boolean
	 */
	public $spam = false;

	/**
	 * The news flag
	 *
	 * @var boolean
	 */
	public $news = false;

	/**
	 * Whether this user's been validated.
	 *
	 * @var boolean
	 */
	public $validated = false;

	/**
	 * Whether this user has completed their registration
	 *
	 * @var boolean
	 */
	public $completed = false;

	/**
	 * Factory. Creates a User VO from a rowset object.
	 *
	 * @return Core_Services_User_VO
	 */
	public static function fromArray ($values)
	{
		$user = new Core_Services_User_VO();

		foreach ($user as $key => $value)
		{
			if (in_array($key, Core_Services_User_VO::$dateFields))
			{
				$user->{$key} = date_create($values[$key]);
			}
			else if (!empty($values[$key]))
			{
				$user->{$key} = $values[$key];
			}
		}

		return $user;
	}

	/**
	 * Creates an instance of this class from a database record.
	 *
	 * @return Core_Services_User_VO
	 */
	public static function fromUser ($user)
	{
		$data = $user->toArray();

		return Core_Services_User_VO::fromArray($data);
	}

	/**
	 * Internal list of all fields that need date/time parsing.
	 * 
	 * @var array
	 */
	private static $dateFields = array('created', 'updated');
}
